package com.flydog.taskManager.controller;

import com.flydog.taskManager.common.api.CommonResult;
import com.flydog.taskManager.common.util.DateUtil;
import com.flydog.taskManager.entity.Task;
import com.flydog.taskManager.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.List;

/**
 * @author Cao
 * @description 工作总体控制类
 * @create 2021-05-10
 */
@Slf4j
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    TaskService taskService;

    @GetMapping("/endIn")
    CommonResult<List<? extends Task>> listTaskEndIn(@RequestParam(value = "begin") String begin,
                                                     @RequestParam(value = "end") String end) throws Exception {
        Calendar beginDate = DateUtil.initDateToStartTimeInDay(begin);
        Calendar endDate = DateUtil.initDateToStartTimeInDay(end);
        return CommonResult.success(taskService.listEndIn(beginDate, endDate));
    }

    @GetMapping("/beginIn")
    CommonResult<List<? extends Task>> listTaskBeginIn(@RequestParam(value = "begin") String begin,
                                                       @RequestParam(value = "end") String end) throws Exception {
        Calendar beginDate = DateUtil.initDateToStartTimeInDay(begin);
        Calendar endDate = DateUtil.initDateToStartTimeInDay(end);
        return CommonResult.success(taskService.listBeginIn(beginDate, endDate));
    }
}
